package com.ruoyi.bill.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bill.domain.Industry;
import com.ruoyi.bill.service.IIndustryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 行业分类Controller
 * 
 * @author sfk
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/industry")
public class IndustryController extends BaseController
{
    @Autowired
    private IIndustryService industryService;

    /**
     * 查询行业分类列表
     */
    @RequiresPermissions("bill:industry:list")
    @GetMapping("/list")
    public TableDataInfo list(Industry industry)
    {
        startPage();
        List<Industry> list = industryService.selectIndustryList(industry);
        return getDataTable(list);
    }

    /**
     * 查询全部行业分类列表
     */
//    @RequiresPermissions("bill:industry:list")
    @GetMapping("/listIndustryAll")
    public AjaxResult listIndustryAll()
    {
//        startPage();
        List<Industry> list = industryService.selectIndustryList(null);
        return success(list);
    }

    /**
     * 导出行业分类列表
     */
    @RequiresPermissions("bill:industry:export")
    @Log(title = "行业分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Industry industry)
    {
        List<Industry> list = industryService.selectIndustryList(industry);
        ExcelUtil<Industry> util = new ExcelUtil<Industry>(Industry.class);
        util.exportExcel(response, list, "行业分类数据");
    }

    /**
     * 获取行业分类详细信息
     */
    @RequiresPermissions("bill:industry:query")
    @GetMapping(value = "/{industryId}")
    public AjaxResult getInfo(@PathVariable("industryId") Long industryId)
    {
        return success(industryService.selectIndustryByIndustryId(industryId));
    }

    /**
     * 新增行业分类
     */
    @RequiresPermissions("bill:industry:add")
    @Log(title = "行业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid Industry industry)
    {
        return toAjax(industryService.insertIndustry(industry));
    }

    /**
     * 修改行业分类
     */
    @RequiresPermissions("bill:industry:edit")
    @Log(title = "行业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Industry industry)
    {
        return toAjax(industryService.updateIndustry(industry));
    }

    /**
     * 删除行业分类
     */
    @RequiresPermissions("bill:industry:remove")
    @Log(title = "行业分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{industryIds}")
    public AjaxResult remove(@PathVariable Long[] industryIds)
    {
        return toAjax(industryService.deleteIndustryByIndustryIds(industryIds));
    }
}
